21 #define D(x) cout << #x " is " << x << endl
25 bool can_change
[15][15];
28 #define inside(i, j) (0 <= (i) && (i) < n && 0 <= (j) && (j) < n)
30 void attack(int i
, int j
){
31 if (can_change
[i
][j
]){
32 if (inside(i
-1, j
)) p
[i
-1][j
] = !p
[i
-1][j
];
33 if (inside(i
+1, j
)) p
[i
+1][j
] = !p
[i
+1][j
];
34 if (inside(i
, j
-1)) p
[i
][j
-1] = !p
[i
][j
-1];
35 if (inside(i
, j
+1)) p
[i
][j
+1] = !p
[i
][j
+1];
43 for (int C
=1; C
<=cases
; C
++){
45 if (scanf("%d", &n
) != 1) return 0;
47 memset(p
, 0, sizeof p
);
48 for (int i
=0; i
<n
; ++i
){
49 for (int j
=0; j
<n
; ++j
){
52 can_change
[i
][j
] = true;
54 can_change
[i
][j
] = !x
;
58 memcpy(backup
, p
, sizeof p
);
61 //Brute-force the subset of cells to change in the first row
62 for (int subset
=0; subset
<(1<<n
); ++subset
){
63 memcpy(p
, backup
, sizeof backup
);
65 for (int j
=0; j
<n
; ++j
){
66 if (subset
& (1 << j
)){
72 //Now, deduce the moves for next rows
73 for (int i
=1; i
<n
; ++i
){
74 for (int j
=0; j
<n
; ++j
){
82 //Let's see if this solved it.
84 for (int i
=0; i
<n
; ++i
)
85 for (int j
=0; j
<n
; ++j
)
89 if (ok
) ans
= min(ans
, cnt
);
92 printf("Case %d: %d\n", C
, (ans
< INT_MAX
? ans
: -1));